package sqltest;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCUtils_Query {
    public static void main(String[] args) {
        JDBCUtils_Query query = new JDBCUtils_Query();
        query.testUpdate();
    }
    public void testUpdate(){
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        String sql = "select * from table1";
        ResultSet set = null;
        try {
            connection=JDBCUtils.getConnection();

            preparedStatement = connection.prepareStatement(sql);

//         执行，得到结果集
            set = preparedStatement.executeQuery();

            while(set.next()){
                int id = set.getInt("id");
                String name = set.getString("name");
                System.out.println(id + "\t" + name);
            }
//            System.out.println(update>0?"修改成功！":"修改失败！");
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.close(set,preparedStatement,connection);
        }


    }
}
